<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>学校固定资产管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./lib/layui/css/modules/layer/default/layer.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script src="./js/MD5.js" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" lay-filter="userinfo">
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <fieldset class="layui-elem-field">
                            <legend>温馨提示</legend>
                            <div class="layui-field-box">
                                忘记密码请联系管理员重置
                            </div>
                        </fieldset>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_oldPassWord" class="layui-form-label">原密码</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_oldPassWord" name="OldPassWord" lay-verify="password"
                            placeholder="请输入原密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_newPassWord" class="layui-form-label">新密码</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_newPassWord" name="NewPassWord" lay-verify="pass"
                            placeholder="请输入新密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_secendNewPassWord" class="layui-form-label">确认密码</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_secendNewPassWord" lay-verify="pass|equal" placeholder="请再次确认新密码"
                            autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn layui-btn-lg" style="width:190px" lay-submit=""
                        lay-filter="edit">修改密码</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        layui.use(['form', 'layer', 'jquery'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                // 密码验证
                form.verify({
                    pass: [
                        /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
                    ],
                    equal: function (value, item) { //value：表单的值、item：表单的DOM对象
                        if (value != layui.$('input[name="NewPassWord"]').val()) {
                            return '密码不相同请重新输入！'
                        }
                    },
                    password: [
                        /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
                    ]
                })

                //监听提交
                form.on('submit(edit)',
                    function (data) {
                        data.field.OldPassWord = md5(data.field.OldPassWord);
                        data.field.NewPassWord = md5(data.field.NewPassWord);
                        $.ajax({
                            type: "Put",
                            headers: {
                                "token": sessionStorage.getItem("token")
                            },
                            url: sessionStorage.getItem("api") + "users/reset_password",
                            data: data.field,
                            contentType: "application/x-www-form-urlencoded",
                            dataType: "Json",
                            success: function (res) {
                                if (res.Code == 200) {
                                    layer.closeAll('loading');
                                    layer.msg(res.Data, {
                                        time: 1500
                                    }, function () {
                                        //关闭当前frame
                                        xadmin.close();
                                    })
                                } else {
                                    layer.closeAll('loading');
                                    layer.msg(res.ErrorMessage);
                                }
                            }
                        });
                        return false;
                    });
            });
    </script>

</body>

</html>